#!/user/bin/env node

const Router = require('koa-router');
const router = new Router(),
      log = console.log;

router.prefix('/authors');

router.get('/',async (ctx)=>{
  const {page,limit} = ctx.query;
  //console.log('req:',ctx.headers);
  log('user-agent:',ctx.header['user-agent']);
  ctx.body = `得到分页查询漫画书作者列表:page=${page},limit=${limit}`;
});

router.get('/:authorName/',async (ctx)=>{
  const {authorName} = ctx.query; 
  log('name:',authorName);
  ctx.body = `按作者名称查询:name=${authorName}`;
});

router.post('/',async (ctx)=>{
  //log(ctx.request.body);
  const {authorName} = ctx.request.body;
  log('name:',authorName);
  ctx.body = `添加新的漫画书作者:name=${authorName}`;
})

router.put('/:id',(ctx)=> {
  //log(ctx.params)
  const {id} = ctx.params;
  log(id);
  ctx.body = `修改某 ID 的漫画书作者名称:id=${id}`;
});
router.delete('/:id',(ctx)=>{
  const {id} = ctx.params;
  log(id);
  ctx.body = `删除某ID的漫画书作者信息:id=${id}`;
});

module.exports = router;
